package day_2022_12_to_3.day;

/**
 * @author haomin
 * @date 2022/12/12 19:11
 **/
public class Day12_12_Num1781 {
    class Solution {
        public int beautySum(String s) {
            int n = s.length();
            int ans = 0;
            for(int i = 0; i < n; ++i) {
                int[] arr = new int[26];
                for(int j = i; j < n; ++j) {
                    arr[s.charAt(j) - 'a']++;
                    int max = 0, min = n;
                    for(int k = 0; k < arr.length; ++k) {
                        if(arr[k] == 0) continue;
                        max = Math.max(max, arr[k]);
                        min = Math.min(min, arr[k]);
                    }
                    ans += (max - min);
                }
            }
            return ans;
        }
    }
}